//
// Created by 谢哲 on 2021/5/17.
//

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
    int N;
    cin >> N;

    map<string, int> sdata;

    int cnt = 0;

    for (int i=0; i<N; ++i) {
        string s1, s2;
        cin >> s1 >> s2;
        s1 = s1.substr(0, 2);
        if (s1!=s2) {
            string pair_s = s2 + s1;
            if (sdata.find(pair_s) != sdata.end()) {
                cnt += sdata[pair_s];
            }
        }
        if (sdata.find(s1 + s2) == sdata.end()) {
            sdata[s1 + s2] = 0;
        }
        sdata[s1+s2] += 1;
    }

    cout << cnt;

    return 0;
}
